package com.recycle.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.recycle.common.annotation.Log;
import com.recycle.common.core.controller.BaseController;
import com.recycle.common.core.domain.CommonResult;
import com.recycle.common.enums.BusinessType;
import com.recycle.system.domain.WasteResourceType;
import com.recycle.system.service.IWasteResourceTypeService;
import com.recycle.common.utils.poi.ExcelUtil;
import com.recycle.common.core.page.TableDataInfo;

/**
 * 再生资源类型信息Controller
 *
 * @author recycle
 * @date 2023-03-11
 */
@RestController
@RequestMapping("/system/type")
@Api(tags = "再生资源类型信息")
public class WasteResourceTypeController extends BaseController
{
    @Autowired
    private IWasteResourceTypeService wasteResourceTypeService;

    /**
     * 查询再生资源类型信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    @ApiOperation("")
    public TableDataInfo list(WasteResourceType wasteResourceType)
    {
        startPage();
        List<WasteResourceType> list = wasteResourceTypeService.selectWasteResourceTypeList(wasteResourceType);
        return getDataTable(list);
    }

    /**
     * 导出再生资源类型信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "再生资源类型信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("")
    public void export(HttpServletResponse response, WasteResourceType wasteResourceType)
    {
        List<WasteResourceType> list = wasteResourceTypeService.selectWasteResourceTypeList(wasteResourceType);
        ExcelUtil<WasteResourceType> util = new ExcelUtil<WasteResourceType>(WasteResourceType.class);
        util.exportExcel(response, list, "再生资源类型信息");
    }

    /**
     * 获取再生资源类型信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{resourceTypeId}")
    @ApiOperation("")
    public CommonResult getInfo(@PathVariable("resourceTypeId") Long resourceTypeId)
    {
        return success(wasteResourceTypeService.selectWasteResourceTypeByResourceTypeId(resourceTypeId));
    }

    /**
     * 新增再生资源类型信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "再生资源类型信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("")
    public CommonResult add(@RequestBody WasteResourceType wasteResourceType)
    {
        return toAjax(wasteResourceTypeService.insertWasteResourceType(wasteResourceType));
    }

    /**
     * 修改再生资源类型信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "再生资源类型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("")
    public CommonResult edit(@RequestBody WasteResourceType wasteResourceType)
    {
        return toAjax(wasteResourceTypeService.updateWasteResourceType(wasteResourceType));
    }

    /**
     * 删除再生资源类型信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "再生资源类型信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resourceTypeIds}")
    @ApiOperation("")
    public CommonResult remove(@PathVariable Long[] resourceTypeIds)
    {
        return toAjax(wasteResourceTypeService.deleteWasteResourceTypeByResourceTypeIds(resourceTypeIds));
    }
}
